package com.wthink.hzgj.station.data

import com.wthink.hzgj.data.BusRepository
import com.wthink.hzgj.data.repository.DefaultBusRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class DefaultStationRepository : StationRepository {

    val busRepository: BusRepository = DefaultBusRepository()

    override suspend fun getStationList(line: String, updir: Boolean): List<Station> {
        return withContext(Dispatchers.IO) {
            val list = busRepository.getStationList(line, updir).map {
                Station(it.station, it.name, it.id)
            }

            if (list.isNotEmpty()) {
                list.last().end = true
            }

            list
        }
    }

}